#include <stdlib.h>
#include <string.h>
#include <assert.h>

#include "../src/struct_util.h"

#define BUFFER_SIZE 1024
static uint8_t buffer[BUFFER_SIZE] = {0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x00}; // "123456789"
static int fill_value = 0;

int number_u8_unpack_check()
{
    const int n = 1;
    uint32_t value = 0;
    assert(n == struct_util_unpack(buffer, ">b", &value));
    assert(value == 0x31ul);
    return 0;
}
int number_u16_unpack_check()
{
    const int n = 2;
    uint32_t value = 0;

    assert(n == struct_util_unpack(buffer, ">h", &value));
    assert(value == 0x3132ul);

    return 0;
}
int number_u24_unpack_check()
{
    const int n = 3;
    uint32_t value = 0;

    assert(n == struct_util_unpack(buffer, ">t", &value));
    assert(value == 0x313233ul);
    return 0;
}
int number_u32_unpack_check()
{
    const int n = 4;
    uint32_t value = 0;

    assert(n == struct_util_unpack(buffer, ">i", &value));
    assert(value == 0x31323334ul);
    return 0;
}
int number_u64_unpack_check()
{
    const int n = 8;
    uint64_t value = 0;

    assert(n == struct_util_unpack(buffer, ">l", &value));
    assert(value == 0x3132333435363738ul);
    return 0;
}
int string_unpack_check()
{
    char str[20] = "";
    const int n = 8;
    memset(str, 'a', sizeof(str));
    assert(n == struct_util_unpack(buffer, "8s", str));
    assert(0 == strcmp(str, "12345678"));

    return 0;
}

int main(int argc, char const *argv[])
{
    number_u8_unpack_check();
    number_u16_unpack_check();
    number_u24_unpack_check();
    number_u32_unpack_check();
    string_unpack_check();
    return 0;
}
